
#delimit;
glo star_level "star(* 0.05 ** 0.01 *** 0.001)";

* Table A1: Summary of Treatments and Key Features;
* Made in Latex;


* Table A2 - Average worker characteristics by treatment condition;
#delimit;
use "${data}\worker.dta", replace;
drop if below5_tasks == 1;
gen cnt = 1;

global vlist age male married white college high_income masters tasks_attempted tasks_comp multiplier time_instructions time_comprehension avg_time_round time_experiment cnt;

gen F = .; gen p_F = .;

foreach t in "cf0" "cf1" "ea1" "ep0" "ep1" {; 
	qui reg trt_`t' age male married white college high_income masters; 
	test age male married white college high_income masters;
	replace F = e(F) if trt_`t'==1; loc p = Ftail(e(df_m), e(df_r), e(F)); replace p_F = `p' if trt_`t' == 1;
};
 
collapse (sum) cnt (mean) age male married white college high_income masters tasks_comp tasks_attempted multiplier time_instructions time_comprehension avg_time_round time_experiment, by(condition);

foreach v in cnt {; gen temp="&"+string(`v',"%15.0fc"); drop `v'; rename temp `v';};
foreach v in age male married white college high_income masters tasks_attempted tasks_comp multiplier time_instructions time_comprehension avg_time_round time_experiment {; gen temp="&"+string(`v',"%15.2f" ); drop `v'; rename temp `v';};

replace multiplier = "&--" if multiplier == "&.";
foreach v in $vlist {; rename `v' val`v';};
reshape long val, i(condition) j(var) string;
reshape wide val, i(var) j(condition);

gen order=.; local n 1; foreach v in $vlist {; replace order=`n' if var=="`v'"; local ++n;}; sort order; drop order;

gen     label= "";
replace label="Age"                                if var=="age";
replace label="Male"                               if var=="male";
replace label="Married"                            if var=="married";
replace label="White"                              if var=="white";
replace label="Completed college"                  if var=="college";
replace label="Income $>$ 75,000"                  if var=="high_income";
replace label="Has masters certification"          if var=="masters";
replace label="Encryptions attempted"              if var=="tasks_attempted";
replace label="Encryptions completed"              if var=="tasks_comp";
replace label="Average multiplier"                 if var=="multiplier";
replace label="Average time spent in each round"   if var=="avg_time_round";
replace label="Time spent in instructions"         if var=="time_instructions";
replace label="Time spent in comprehension screen" if var=="time_comprehension";
replace label="Total time in experiment"           if var=="time_experiment";
replace label="\(N\) (Workers)"                    if var=="cnt";

gen end="\\"; replace end="\\\midrule" if var == "masters" | var == "time_experiment";
 
drop var;
order label val1 val2 val3 val4 val5 end; 

outsheet using "${res}/worker-summ.tex", replace noquote nonames delimiter(" ");


* Table A3 - Heterogeneity in redistribution;
#delimit;
use "${data}\spectator.dta", replace;

gen old           = (age>=50)                  ; gen young        = (age<50)                  ;
gen college       = (education>=5)             ; gen nocollege    = (education<5)             ;
gen high_numeracy = (numeracy=="numeracy_high"); gen low_numeracy = (numeracy=="numeracy_low");
gen high_income   = (hh_income>=9)             ; gen low_income   = (hh_income<=8)            ;
gen female        = 1-male;

gen pi_pct = pi;

replace pi = pi/100;  // As a fraction;
replace pi = pi*10;   // Scale to represent a 10 pp change; 
replace pi = 1-pi;    // Replace pi for 1-pi; 
gen cons=1; 

loc vlist "fair_work fair_talent fair_luck fair_connections better_life luck_connections issues_democrat issues_republican redistribute_never redistribute_luck redistribute_regardless income_distribution economic_liberal social_conservative higher_income";  
foreach v of local vlist {; recode `v' (1/2 = 1) (3/5 = 0); };

tempfile data; save `data', replace;

loc vlist "young old male female married white black college nocollege working_ft high_numeracy low_numeracy retired low_income high_income `vlist'";

foreach v of local vlist {;
	
	use if `v' != . & info == "no" using `data', replace;

	if "`v'" == "fair_work"               global label "Influece~of~hard~work~is~fair"     ;
	if "`v'" == "fair_luck"               global label "Influece~of~luck~is~fair"          ;
	if "`v'" == "fair_talent"             global label "Influece~of~talent~is~fair"        ;
	if "`v'" == "fair_connections"        global label "Influece~of~connections~is~fair"   ;
	if "`v'" == "better_life"             global label "Hard~work~brings~a~better~life"    ;
	if "`v'" == "luck_connections"        global label "Success~is~about~luck"             ;
	if "`v'" == "issues_democrat"         global label "Tend~to~side~with~democrats"       ;
	if "`v'" == "issues_republican"       global label "Tend~to~side~with~republicans"     ;
	if "`v'" == "redistribute_regardless" global label "Gov't~eliminate~income~differences";
	if "`v'" == "redistribute_never"      global label "Gov't~should~never~redistribute"   ;
	if "`v'" == "redistribute_luck"       global label "Gov't~redistribute~to~correct~luck";
	if "`v'" == "income_distribution"     global label "Income~dist.~in~the~US~is~fair"    ;
	if "`v'" == "social_conservative"     global label "Conservative~on~social~issues"     ;
	if "`v'" == "higher_income"           global label "Key~to~success~own~hands"          ;
	if "`v'" == "economic_liberal"        global label "Oppose~gov't~interventions"        ;
	if "`v'" == "young"                   global label "Under~50-years~old"                ;
	if "`v'" == "old"                     global label "Over~50-years~old"                 ;
	if "`v'" == "male"                    global label "Male"                              ;
	if "`v'" == "female"                  global label "Female"                            ;
	if "`v'" == "married"                 global label "Married"                           ;
	if "`v'" == "white"                   global label "White"                             ;
	if "`v'" == "black"                   global label "Black"                             ;
	if "`v'" == "college"                 global label "Completed~college"                 ;
	if "`v'" == "nocollege"               global label "Less~than~college"                 ;
	if "`v'" == "working_ft"              global label "Works~full-time"                   ;
	if "`v'" == "working_pt"              global label "Works~part-time"                   ;
	if "`v'" == "retired"                 global label "Retired"                           ;
	if "`v'" == "high_numeracy"           global label "High~numeracy"                     ; 
	if "`v'" == "low_numeracy"            global label "Low~numeracy"                      ;
	if "`v'" == "houseowner"              global label "House~owner"                       ;
	if "`v'" == "high_income"             global label "HH~income~above~100k"              ; 
	if "`v'" == "low_income"              global label "HH~income~below~100k"              ; 

	gen char    = `v'   ;
	gen char_pi = `v'*pi;

	eststo clear;	
    eststo: reg shr_red char                 if condition == "CF", robust cluster(id); rename char char_cons;
	eststo: reg shr_red char_cons char_pi pi if condition == "CF", robust cluster(id); rename char_cons char;
    eststo: reg shr_red char                 if condition == "EA", robust cluster(id); rename char char_cons;
	eststo: reg shr_red char_cons char_pi pi if condition == "EA", robust cluster(id);
	
	loc v = subinstr("`v'", "_", "-", .);
	
	esttab using "${res}/redist-het-`v'.tex", rename(char_pi char) keep(char) coeflabels(char "${label}") replace nonotes nonumbers nomtitles se nolines nogaps noobs b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&");
	
};


* Table A4 - Fraction redistributed as a function of $1 - \pi$ and information treatment;

* Panel A. Average redistribution;
#delimit;
use "${data}\spectator.dta", replace;
drop if condition == "EP";

rename info has_info;
gen info = (has_info == "yes");

eststo clear;
eststo: reg shr_red               info if condition == "CF",        robust cluster(id);
eststo: reg shr_red               info if condition == "EA",        robust cluster(id); gen cons=1; ren info info0; gen info = cf*info;
eststo: reg shr_red cf info0 cons info                     , nocons robust cluster(id); drop cons;

esttab using "${res}/redist-cons-info.tex", rename(cf _cons) keep(info _cons) coeflabels(_cons "Constant"  info "Info~$\pi$") replace nonotes nonumbers nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Redistributive~decisions CPAREN"));;


* Panel B. Linear slope;
#delimit;
use "${data}\spectator.dta", replace;
drop if condition == "EP";

replace pi = pi/100;   // As a fraction;
replace pi = pi - 0.5; // Constant = Intercept in Figure;
replace pi = pi*10;    // Scale to represent a 10 pp change; 
replace pi = 1 - pi;  // Use 1-pi instead of pi;
rename info has_info;

gen info = (has_info == "yes");
gen pi_info = pi*info;

eststo clear;
eststo: reg shr_red pi info pi_info if condition == "CF" , robust cluster(id);
eststo: reg shr_red pi info pi_info if condition == "EA" , robust cluster(id); gen cons=1; rename pi pi0; rename info info0; rename pi_info pi_info0; gen c = cf; gen pi = pi0*cf; gen info = info0*cf; gen pi_info = pi_info0*cf; 
eststo: reg shr_red cons c pi0 pi info0 info pi_info pi_info0, robust nocons cluster(id); drop c pi info pi_info;

esttab using "${res}/redist-slope-info.tex", rename(c _cons) keep(pi info pi_info _cons) coeflabels(pi "1-$\pi$" info "Info~$\pi$" pi_info "1-$\pi~\times$~Info~$\pi$" _cons "Constant")  replace nonotes nonumbers nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Redistributive~decisions CPAREN"));;


* Table A5 - Gap in mean redistribution between lucky outcomes and lucky opportunities as a function of $1 - \pi$ and information treatment;
#delimit;
use "${data}/spectator.dta", replace;
drop if condition == "EP";

rename info has_info;
gen info = (has_info == "yes");
replace pi_bin = 13-pi_bin; // Change to use 1-pi bins;

levelsof pi_bin, local(bins); foreach p of local bins {; gen bin_`p' = (pi_bin == `p'); gen cf_bin_`p' = bin_`p'*cf; };

eststo clear;
eststo: reg shr_red bin_* cf_bin* if info == 0, nocons robust cluster(id);
eststo: reg shr_red bin_* cf_bin* if info == 1, nocons robust cluster(id);

rename cf cf0; rename bin* bin0*; rename cf_bin* cf_bin0*;

gen c  = info; 
gen cf = cf0*info; 

forval p =1/12 {; 
	gen bin_`p'   = bin0_`p'*info;    // Info x Pi_bin;
	gen cf_bin_`p'= info*cf_bin0_`p'; // Info x CF x Pi_bin;
}; 

eststo: reg shr_red bin_* bin0* cf_bin0* cf_bin_*, nocons robust cluster(id); 

esttab using "${res}/redist-gap-info.tex", keep(cf_bin_*) replace nonotes nonumbers nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&")
coeflabels(bin_1  "1-$\pi = 0.50$"           cf_bin_1  "Lucky ~ Opportunities ~ $\times$ ~ 1-$\pi = 0.00$" 
           bin_2  "1-$\pi \in (0.45, 0.50)$" cf_bin_2  "Lucky ~ Opportunities ~ $\times$ ~ 1-$\pi \in (0.00, 0.05]$"
           bin_3  "1-$\pi \in (0.40, 0.45]$" cf_bin_3  "Lucky ~ Opportunities ~ $\times$ ~ 1-$\pi \in (0.05, 0.10]$"
           bin_4  "1-$\pi \in (0.35, 0.40]$" cf_bin_4  "Lucky ~ Opportunities ~ $\times$ ~ 1-$\pi \in (0.10, 0.15]$"
           bin_5  "1-$\pi \in (0.30, 0.35]$" cf_bin_5  "Lucky ~ Opportunities ~ $\times$ ~ 1-$\pi \in (0.15, 0.20]$"
           bin_6  "1-$\pi \in (0.25, 0.30]$" cf_bin_6  "Lucky ~ Opportunities ~ $\times$ ~ 1-$\pi \in (0.20, 0.25]$"
           bin_7  "1-$\pi \in (0.20, 0.25]$" cf_bin_7  "Lucky ~ Opportunities ~ $\times$ ~ 1-$\pi \in (0.25, 0.30]$"
           bin_8  "1-$\pi \in (0.15, 0.20]$" cf_bin_8  "Lucky ~ Opportunities ~ $\times$ ~ 1-$\pi \in (0.30, 0.35]$"
           bin_9  "1-$\pi \in (0.10, 0.15]$" cf_bin_9  "Lucky ~ Opportunities ~ $\times$ ~ 1-$\pi \in (0.35, 0.40]$"
           bin_10 "1-$\pi \in (0.05, 0.10]$" cf_bin_10 "Lucky ~ Opportunities ~ $\times$ ~ 1-$\pi \in (0.40, 0.45]$"
           bin_11 "1-$\pi \in (0.00, 0.05]$" cf_bin_11 "Lucky ~ Opportunities ~ $\times$ ~ 1-$\pi \in (0.45, 0.50)$"
           bin_12 "1-$\pi = 0.00$"           cf_bin_12 "Lucky ~ Opportunities ~ $\times$ ~ 1-$\pi = 0.50$"          
           info   "Info~$\pi$"              _cons  "Constant")  stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Redistributive~decisions CPAREN"));


test cf_bin_1 cf_bin_2 cf_bin_3 cf_bin_4 cf_bin_5 cf_bin_6 cf_bin_7 cf_bin_8 cf_bin_9 cf_bin_10 cf_bin_11 cf_bin_12;


* Table A6 - Correlation between redistribution behavior and political and social preferences;
#delimit;
use "${data}\spectator.dta", replace;
keep if info == "no";
drop if ep   == 1;

glo vlist "fair_work fair_talent fair_luck fair_connections better_life luck_connections issues_democrat issues_republican redistribute_never redistribute_luck redistribute_regardless income_distribution economic_liberal social_conservative higher_income";  

pca $vlist; predict pc1, score;

glo vlist $vlist pc1;

foreach v in $vlist {; replace `v' = `v'*-1; }; // Higher values = agree;

foreach v in $vlist shr_red {; 
	replace `v' = `v'*-1; // Higher values = agree;
	bys condition: egen `v'_mean = mean(`v');
	bys condition: egen  `v'_sd  =   sd(`v');
	replace `v' = (`v' - `v'_mean)/`v'_sd; drop `v'_mean `v'_sd;
};


glo reverse "pc1 fair_work fair_talent fair_luck fair_connections better_life luck_connections issues_republican redistribute_never income_distribution economic_liberal social_conservative higher_income";  

foreach v in $reverse {; replace `v' = `v'*-1; }; // Reverse-code;

egen z_score = rowmean(fair_work fair_talent fair_luck fair_connections better_life luck_connections issues_democrat issues_republican redistribute_never redistribute_luck redistribute_regardless income_distribution economic_liberal social_conservative higher_income);

glo vlist $vlist z_score;

foreach v of global vlist {; 

eststo clear;
eststo: reg `v' shr_red            if condition == "CF", robust  cluster(id);
eststo: reg `v' shr_red            if condition == "EA", robust  cluster(id); rename shr_red shr_red0; gen shr_red = shr_red0*cf; 
eststo: reg `v' shr_red shr_red0 cf                    , robust  cluster(id); drop   shr_red; rename shr_red0 shr_red;

if "`v'" == "fair_work"               global label "Influece~of~hard~work~is~fair"     ;
if "`v'" == "fair_luck"               global label "Influece~of~luck~is~fair"          ;
if "`v'" == "fair_talent"             global label "Influece~of~talent~is~fair"        ;
if "`v'" == "fair_connections"        global label "Influece~of~connections~is~fair"   ;
if "`v'" == "better_life"             global label "Hard~work~brings~a~better~life"    ;
if "`v'" == "luck_connections"        global label "Success~is~about~luck"             ;
if "`v'" == "issues_democrat"         global label "Tend~to~side~with~democrats"       ;
if "`v'" == "issues_republican"       global label "Tend~to~side~with~republicans"     ;
if "`v'" == "redistribute_regardless" global label "Gov't~eliminate~income~differences";
if "`v'" == "redistribute_never"      global label "Gov't~should~never~redistribute"   ;
if "`v'" == "redistribute_luck"       global label "Gov't~redistribute~to~correct~luck";
if "`v'" == "income_distribution"     global label "Income~dist.~in~the~US~is~fair"    ;
if "`v'" == "social_conservative"     global label "Conservative~on~social~issues"     ;
if "`v'" == "higher_income"           global label "Key~to~success~own~hands"          ;
if "`v'" == "economic_liberal"        global label "Oppose~gov't~interventions"        ;
if "`v'" == "pc1"                     global label "PCA~first~component"               ;
if "`v'" == "z_score"                 global label "z-score"                         ;
	
if !inlist("`v'", "issues_democrat", "redistribute_luck", "redistribute_regardless") glo label "${label}~OPAREN - CPAREN";

loc stats "";
if inlist("`v'", "pc1", "z_score") loc stats `"stats(r2, fmt(%4.3f) layout("\multicolumn{1}{c}{@}") labels("R-squared"))"';

loc v = subinstr("`v'", "_", "-", .);

esttab using "${res}/pred-`v'.tex", keep(shr_red) coeflabels(shr_red "${label}") `stats' replace nonotes nonumbers nomtitles se nolines nogaps noobs b(3) ${star_level}  booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&");

};



* Table A7 - Number of encryptions completed and worker multiplier;
#delimit;
use "${data}\worker.dta", replace;

drop if tasks_comp <5;
gen cf = (inlist(condition,1,2)); drop if cf == 1;
gen ep = (inlist(condition,4,5)); drop if ep == 1;

gen ltasks_comp = log(tasks_comp);

recode multiplier (1/1.49 = 1) (1.5/1.99 = 2) (2/2.49 = 3) (2.5/2.99 = 4) (3/3.49 = 5) (3.5/4 = 6), gen(multiplier_bin);

levelsof multiplier_bin, local(bins); foreach p of local bins {; gen bin_`p' = (multiplier_bin == `p'); }; drop bin_6;

 eststo clear;
 eststo: reg tasks_comp  multiplier    , robust cluster(id);
 eststo: reg tasks_comp  bin_*         , robust cluster(id);

esttab using "${res}/actual-eff-m.tex", replace nonotes nonumbers nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&")
coeflabels(multiplier "Multiplier" 
		   bin_1  "Multiplier~$\in [1.0, 1.5)$"        
           bin_2  "Multiplier~$\in [1.5, 2.0)$"
           bin_3  "Multiplier~$\in [2.0, 2.5)$"
           bin_4  "Multiplier~$\in [2.5, 3.0)$"
           bin_5  "Multiplier~$\in [3.0, 3.5)$"
           bin_6  "Multiplier~$\in [3.5, 4.0]$"
		   _cons  "Constant") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Wokers CPAREN"));


	   
* Table A8 - Fraction redistributed as a function of $\pi$ in baseline and ex-post lucky opportunities;

* Panel A. Average redistribution;
#delimit;
use "${data}\spectator.dta", replace;
drop if condition == "CF";
drop if info      == "yes";

replace pi = pi/100;
eststo clear;
eststo: reg shr_red          if condition == "EA",        robust cluster(id);
eststo: reg shr_red          if condition == "EP",        robust cluster(id); gen cons=1;
eststo: reg shr_red ea cons                      , nocons robust cluster(id); drop cons; 

esttab using "${res}/redist-cons-ea-ep.tex", rename(ea _cons) keep(_cons) coeflabels(_cons "Constant") replace nonotes nonumbers nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Redistributive~decisions CPAREN"));

* Panel B. Slope;
#delimit;
use "${data}\spectator.dta", replace;
drop if condition == "CF";
drop if info      == "yes";

replace pi = pi/100;   // As a fraction;
replace pi = pi - 0.5; // Constant = Intercept in Figure;
replace pi = pi*10;    // Scale to represent a 10 pp change; 
replace pi = 1 - pi;  // Use 1-pi instead of pi;


eststo clear;
eststo: reg shr_red pi            if condition == "EA",        robust cluster(id);
eststo: reg shr_red pi            if condition == "EP",        robust cluster(id); gen cons=1; rename pi pi0; gen c = ea; gen pi = pi0*ea; 
eststo: reg shr_red pi cons c pi0                     , nocons robust cluster(id); drop c pi; 

esttab using "${res}/redist-slope-ea-ep.tex", keep(pi _cons) rename(c _cons) coeflabels(pi "1 - $\pi$" _cons "Constant")  replace nonotes nonumbers nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Redistributive~decisions CPAREN"));


* Pane C. Bins;

#delimit;
use "${data}\spectator.dta", replace;
drop if condition == "CF";
drop if info      == "yes";

replace pi_bin = 13-pi_bin; // Change to use 1-pi bins;
levelsof pi_bin, local(bins); foreach p of local bins {; gen bin_`p' = (pi_bin == `p'); }; 

eststo clear;
eststo: reg shr_red bin_* if condition == "EA", nocons robust cluster(id);
eststo: reg shr_red bin_* if condition == "EP", nocons robust cluster(id); 

drop bin_*; foreach p of local bins {; gen c_`p'=(pi_bin == `p'); }; 
			 foreach p of local bins {; gen bin_`p' = c_`p'*ea ; }; gen c = ea; 
						 
eststo: reg shr_red c_* bin_*, nocons robust cluster(id);

esttab using "${res}/redist-bins-ea-ep.tex", keep(bin*) replace nonotes nonumbers nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&")
coeflabels(
bin_1  "1-$\pi = 0.00$" 
bin_2  "1-$\pi \in (0.00, 0.05]$" 
bin_3  "1-$\pi \in (0.05, 0.10]$" 
bin_4  "1-$\pi \in (0.10, 0.15]$" 
bin_5  "1-$\pi \in (0.15, 0.20]$" 
bin_6  "1-$\pi \in (0.20, 0.25]$" 
bin_7  "1-$\pi \in (0.25, 0.30]$" 
bin_8  "1-$\pi \in (0.30, 0.35]$" 
bin_9  "1-$\pi \in (0.35, 0.40]$" 
bin_10 "1-$\pi \in (0.40, 0.45]$" 
bin_11 "1-$\pi \in (0.45, 0.50)$" 
bin_12 "1-$\pi = 0.50$" _cons "Constant") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Redistributive~decisions CPAREN"));



* Table A9 - Perceived worker effort and worker multiplier;
#delimit;
use "${data}\spectator.dta", replace;
keep if condition == "EA";
keep if is_rand_round;

recode random_m (1/1.49 = 1) (1.5/1.99 = 2) (2/2.49 = 3) (2.5/2.99 = 4) (3/3.49 = 5) (3.5/4 = 6), gen(random_m_bins);
levelsof random_m_bins, local(bins); foreach p of local bins {; gen bin_`p' = (random_m_bins == `p'); }; drop bin_6;

gen lavg_effort = log(avg_effort);

 eststo clear;
 eststo: reg  avg_effort random_m, robust cluster(id);
 eststo: reg  avg_effort bin_*   , robust cluster(id);

esttab using "${res}/beliefs-eff-m.tex", replace nonotes nonumbers nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&")
coeflabels(random_m "Multiplier" 
		   bin_1  "Multiplier~$\in [1.0, 1.5)$"        
           bin_2  "Multiplier~$\in [1.5, 2.0)$"
           bin_3  "Multiplier~$\in [2.0, 2.5)$"
           bin_4  "Multiplier~$\in [2.5, 3.0)$"
           bin_5  "Multiplier~$\in [3.0, 3.5)$"
           bin_6  "Multiplier~$\in [3.5, 4.0]$"
		   _cons  "Constant") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Spectators CPAREN"));;
	
* Table A10 - Fraction redistributed on polynomials of the multiplier difference;
#delimit;
use "${data}\spectator.dta", replace;
drop if condition == "CF";
drop if condition == "EP";

replace pi = pi/100;   // As a fraction;
replace pi = pi - 0.5; // Constant = Intercept in Figure;
replace pi = pi*10;    // Scale to represent a 10 pp change; 
replace pi = 1 - pi;   // Use 1-pi instead of pi;

gen has_info = (info == "yes");

eststo clear; forvalues i = 1(1)5 {; gen spline_lin`i' =  diff_m^`i'; aorder; eststo: reg shr_red spline_lin1-spline_lin`i' if has_info ==0, cluster(id); }; esttab, se ${star_level};
esttab using "${res}/redist-poly-diff.tex", keep(spline*) 
coeflabels(spline_lin1 "(Multiplier~difference)$^1$" spline_lin2 "(Multiplier~difference)$^2$" spline_lin3 "(Multiplier~difference)$^3$" spline_lin4 "(Multiplier~difference)$^4$" spline_lin5 "(Multiplier~difference)$^5$" pi "$\pi$")  replace nonotes nonumbers nomtitles se nolines nogaps noobs b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Redistributive~decisions CPAREN"));



* Table A11 - Determinants of redistribution;
#delimit;
use "${data}\spectator.dta", replace;
drop if condition == "CF";
drop if condition == "EP";

replace pi = pi/100;   // As a fraction;
replace pi = pi - 0.5; // Constant = Intercept in Figure;
replace pi = pi*10;    // Scale to represent a 10 pp change; 
replace pi = 1 - pi;   // Use 1-pi instead of pi;

gen has_info = (info == "yes");

eststo clear; 
eststo: reg shr_red diff_m    if has_info ==0, cluster(id);
eststo: reg shr_red        pi if has_info ==0, cluster(id);
eststo: reg shr_red diff_m pi if has_info ==0, cluster(id);
esttab, se ${star_level};
esttab using "${res}/redist-determ-noinfo.tex", keep(diff_m pi _cons) 
coeflabels(diff_m "Multiplier~difference" pi "Prob.~best~performer~lost" _cons "Constant") replace nonotes nonumbers nomtitles se nolines nogaps noobs b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Redistributive~decisions CPAREN"));

#delimit;
eststo clear; 
eststo: reg shr_red diff_m     if has_info ==0, cluster(id);
eststo: reg shr_red         pi if has_info ==0, cluster(id);
eststo: reg shr_red diff_m  pi if has_info ==0, cluster(id);
esttab using "${res}/redist-determ-info.tex", keep(diff_m pi _cons) 
coeflabels(diff_m "Multiplier~difference" pi "Prob.~best~performer~lost" _cons "Constant") replace nonotes nonumbers nomtitles se nolines nogaps noobs b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Redistributive~decisions CPAREN"));


* Table B1 - Fraction of spectators who do not redistribute across conditions;

#delimit;
glo N = 12;
use "${data}\spectator.dta", replace;
drop if condition == "EP" ;

bys id: gen one = (_n == 1);
gen no_red = (redistribute == 0);
bys id: egen sum_nored  = sum(no_red);
gen libert_${N}_12 = (sum_nored >= ${N});

replace pi = pi/100; 
replace pi = pi*10; 
rename info has_info;

gen info     = (has_info == "yes");
gen iop      = (condition != "CF");
gen iop_info = iop*info;

gen college    = (education>=5);
levelsof region   , local(reg); foreach r of local reg {; gen reg_`r' = (region    == "`r'"); }; drop reg_northeast; 
levelsof hh_income, local(inc); foreach i of local inc {; gen inc_`i' = (hh_income == `i'  ); }; drop inc_1; 
gen     time_tot = time_yourtask + time_aboutworkers + time_comprehension + time_decision + time_effort + time_beliefs;
replace time_tot = time_tot/60;

gen miss_time = (time_tot == .); qui sum time_tot; replace time_tot = r(mean) if time_tot == .;

glo xlist "pi age male married children_under18 white black hispanic college time_tot working_ft working_pt retired own_house total_numeracy inc_* reg_* ";

eststo clear;
eststo: reghdfe libert_${N}_12 iop                     , cluster(id) noabsorb;
eststo: reghdfe libert_${N}_12 iop info                , cluster(id) noabsorb;
eststo: reghdfe libert_${N}_12 iop info iop_info       , cluster(id) noabsorb;
eststo: reghdfe libert_${N}_12 iop info iop_info $xlist, cluster(id) absorb(miss_* passed_att q*_att* mobile_device round_nr);

esttab using "${res}\nored-info.tex", keep(iop info iop_info _cons) 
	coeflabels(iop "Lucky~Opportunities" info "Info~$\pi$" iop_info "Lucky~Opportunities~$\times$~Info~$\pi$" _cons "Constant")  
	replace nonotes nonumbers nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Redistributive~decisions CPAREN"));



* Table B2 - Fraction redistributed as a function of $\pi$ for spectators who redistribute something;

* Panel A;
#delimit;
glo N = 12;
use "${data}\spectator.dta", replace;
bys id: gen one = (_n == 1);
gen no_red = (redistribute == 0);
bys id: egen sum_nored  = sum(no_red);
gen libert_${N}_12 = (sum_nored >= ${N});

drop if condition      == "EP" ;
drop if info           == "yes";
drop if libert_${N}_12 == 1    ;

replace pi = pi/100;

eststo clear;
eststo: reg shr_red         if condition == "CF",        robust cluster(id);
eststo: reg shr_red         if condition == "EA",        robust cluster(id); gen cons=1; 
eststo: reg shr_red cf cons                     , nocons robust cluster(id); drop cons;

esttab using "${res}/redist-cons-nolibert.tex", rename(cf _cons) keep(_cons) coeflabels(_cons "Constant") replace nonotes nonumbers nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Redistributive~decisions CPAREN"));


* Panel B;
#delimit;
use "${data}\spectator.dta", replace;
bys id: gen one = (_n == 1);
gen no_red = (redistribute == 0);
bys id: egen sum_nored  = sum(no_red);
gen libert_${N}_12 = (sum_nored >= ${N});

drop if condition      == "EP" ;
drop if info           == "yes";
drop if libert_${N}_12 == 1    ;

replace pi = pi/100;   // As a fraction;
replace pi = pi - 0.5; // Constant = Intercept in Figure;
replace pi = pi*10;    // Scale to represent a 10 pp change; 
replace pi = 1 - pi;   // Use 1-pi instead of pi;

eststo clear;
eststo: reg shr_red pi             if condition == "CF",        robust cluster(id);
eststo: reg shr_red pi             if condition == "EA",        robust cluster(id); gen cons=1; rename pi pi0; gen c = cf; gen pi = pi0*cf; 
eststo: reg shr_red pi pi0 cons c                      , nocons robust cluster(id); drop c pi; 

esttab using "${res}/redist-slope-nolibert.tex", keep(pi _cons) rename(c _cons) coeflabels(pi "1 - $\pi$" _cons "Constant")  replace nonotes nonumbers nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Redistributive~decisions CPAREN"));



* Table B3 - Fraction redistributed as a function of $\pi$ in ex-post lucky opportunities and lucky outcomes conditions (only rules-after);

* Panel A. Average redistribution;
#delimit;
use "${data}\spectator.dta", replace;
drop if rules == "before";
drop if info  == "yes";

replace pi = pi/100;

eststo clear;
eststo: reg shr_red         if condition == "CF",        robust cluster(id);
eststo: reg shr_red         if condition == "EP",        robust cluster(id); gen cons=1; 
eststo: reg shr_red cf cons                     , nocons robust cluster(id); 

esttab using "${res}/redist-cons-cf-ep-norules.tex", rename(cf _cons) keep(_cons) coeflabels(_cons "Constant") replace nonotes nonumbers nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Redistributive~decisions CPAREN"));

* Panel B. Slope;
#delimit;
use "${data}\spectator.dta", replace;
drop if rules == "before";
drop if info  == "yes";

replace pi = pi/100;   // As a fraction;
replace pi = pi - 0.5; // Constant = Intercept in Figure;
replace pi = pi*10;    // Scale to represent a 10 pp change; 
replace pi = 1 - pi;   // Use 1-pi instead of pi;

eststo clear;
eststo: reg shr_red pi            if condition == "CF",        robust cluster(id);
eststo: reg shr_red pi            if condition == "EP",        robust cluster(id); gen cons=1; rename pi pi0;  gen c = cf; gen pi = pi0*cf; 
eststo: reg shr_red pi cons c pi0                     , nocons robust cluster(id);

esttab using "${res}/redist-slope-cf-ep-norules.tex", keep(pi _cons) rename(c _cons) coeflabels(pi "$\pi$" _cons "Constant")  replace nonotes nonumbers nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Redistributive~decisions CPAREN"));

* Panel C. Bins;
#delimit;
use "${data}\spectator.dta", replace;
drop if rules == "before";
drop if info  == "yes";

replace pi_bin = 13-pi_bin; // Change to use 1-pi bins;

levelsof pi_bin, local(bins); foreach p of local bins {; gen bin_`p' = (pi_bin == `p'); };

eststo clear;
eststo: reg shr_red bin_* if condition == "CF", nocons robust cluster(id);
eststo: reg shr_red bin_* if condition == "EP", nocons robust cluster(id);

drop bin_*; foreach p of local bins {; gen c_`p'=(pi_bin == `p'); }; 
             foreach p of local bins {; gen bin_`p' = c_`p'*cf ; }; gen c = cf; 

eststo: reg shr_red c_* bin_*, nocons robust cluster(id);

esttab using "${res}/redist-bins-cf-ep-norules.tex", keep(bin*) replace nonotes nonumbers nomtitles se nolines nogaps obslast b(3) ${star_level} booktabs fragment substitute(\_ _ " " "" "&" "&&" "~" " " "-" "$-$" "\\" "&\\" "\multicolumn{1}{c}{" "" "}&" "&" "\sym{***&" "&\sym{***}" "\sym{**&" "&\sym{**}" "\sym{*&" "&\sym{*}" ")&" "&)" "\&)" "\)&" "OPAREN" "(" "CPAREN" ")" "(.&)" "&")
coeflabels(
bin_1  "1-$\pi = 0.00$" 
bin_2  "1-$\pi \in (0.00, 0.05]$" 
bin_3  "1-$\pi \in (0.05, 0.10]$" 
bin_4  "1-$\pi \in (0.10, 0.15]$" 
bin_5  "1-$\pi \in (0.15, 0.20]$" 
bin_6  "1-$\pi \in (0.20, 0.25]$" 
bin_7  "1-$\pi \in (0.25, 0.30]$" 
bin_8  "1-$\pi \in (0.30, 0.35]$" 
bin_9  "1-$\pi \in (0.35, 0.40]$" 
bin_10 "1-$\pi \in (0.40, 0.45]$" 
bin_11 "1-$\pi \in (0.45, 0.50)$" 
bin_12 "1-$\pi = 0.50$" _cons "Constant") stats(N, fmt(%20.0fc) layout("\multicolumn{1}{c}{@}") labels("\(N\)~OPAREN Redistributive~decisions CPAREN"));
